import React, { Component } from 'react'
import { Form, Input, Button, Checkbox } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import axios from 'axios'
import {connect} from 'react-redux'

class Index extends Component {
    render() {
        const onFinish = values => {
            this.props.enter(values)
            // console.log(props)
            console.log(this.props)
            console.log('Received values of form: ', values);
        }
        return (
            <div className="enter-box">
                <Form
                name="normal_login"
                className="login-form"
                initialValues={{ remember: true }}
                onFinish={onFinish}
                
                >
                <Form.Item
                    name="username"
                    rules={[{ required: true, message: '请输入账号!' }]}
                >
                    <Input prefix={<UserOutlined className="site-form-item-icon" />} placeholder="账号" />
                </Form.Item>
                <Form.Item
                    name="password"
                    rules={[{ required: true, message: '请输入密码!' }]}
                >
                    <Input
                    prefix={<LockOutlined className="site-form-item-icon" />}
                    type="password"
                    placeholder="密码"
                    />
                </Form.Item>
                <Form.Item>
                    <Form.Item name="remember" valuePropName="checked" noStyle>
                    <Checkbox>记住我的选择</Checkbox>
                    </Form.Item>

                    <a className="login-form-forgot" href="">
                   忘记密码
                    </a>
                </Form.Item>

                <Form.Item>
                    <Button type="primary" htmlType="submit" className="login-form-button">
                    登录
                    </Button>
                    <a href="">去注册</a>
                </Form.Item>
                </Form>
            </div>
        )
    }
}

const mapStateToProps = (store, props) => {
    return {

    }
}
const mapDispatchToProps = (dispatch,props) => {
    return {
        enter(obj) {
            console.log(111)
            console.log(obj,123,props)
            dispatch(_ => {
                axios.post('/workenter', {
                    phone:obj.username,
                    password:obj.password
                }).then(res => {
                    console.log(1,obj)
                    if(res.data.code === 1) {
                            console.log('登录成功')
                            props.history.push('/index/lunbo')
                    } else{
                            console.log('登录失败')
                    }
                })
            })
        }
    }
}
export default connect(mapStateToProps, mapDispatchToProps)(Index)
